/*
leetcode 435
用贪心
*/
#include<bits/stdc++.h>
using namespace std;
class Solution {
public:
//这里的&要加,前面的static也要加
//<：升序
	static bool cmp(vector<int> &a,vector<int> &b){
		return a[0]<b[0];
	}
    int eraseOverlapIntervals(vector<vector<int>>& intervals) {
    	if(intervals.size()==0) return 0;
    	sort(intervals.begin(),intervals.end(),cmp);
		int end=intervals[0][1];
		int count=0;
		for(int i=1;i<intervals.size();i++){
			if(intervals[i][0]<end){
				end=min(end,intervals[i][1]);
				count++;
			}else{
				end=intervals[i][1];
			}
		}
		return count;
    }
};